// CWHPaccess.h
#pragma once
#include "WPFCaller.h"

namespace Ooganizer
{
	//////////////////////////////////////////////////////////////////////
	//******************************************************************** 
	// DS access Class - Created to easily enforce critical sections and
	//					 share the statically created DS
	//******************************************************************** 
	//////////////////////////////////////////////////////////////////////
	class CWHPaccess
	{
	public:
		////
		// All these statics are put into the DS and shared accross all DLL instances
		// ~Use accessor functions below to modify these
		////
		static HINSTANCE hModule;
		static HHOOK hHook;
		static HookWndItem HList[MAX_PATH];		
		static UINT HListI;
		static char ALLOWED_PROCESS_NAMES[MAX_PATH][MAX_PATH];
		static UINT NUMBER_OF_ALLOWED_PROCESS_NAMES;
		static char ALLOWED_WINDOW_TITLES[MAX_PATH][MAX_PATH];
		static UINT NUMBER_OF_ALLOWED_WINDOW_TITLES;
		static char ALLOWED_WINDOW_CLASSES[MAX_PATH][MAX_PATH];
		static UINT NUMBER_OF_ALLOWED_WINDOW_CLASSES;
		static UINT nLoggingDetail;
		static char LoggingPath[MAX_PATH];

		// Hook Handle
		void set_hHook(HHOOK);
		HHOOK get_hHook();	
			
		// Clears all Shared DS segment's Hook List data 
		// (imp, when releasing the hook)
		void ClearHookSData();	

		////
		// Find,Insert,Deletion of HookWnd
		////
		BOOL InsertHookedWndItem(HookWndItem& Item);												
		BOOL FindHookedWnd(HWND hWnd);				
		HookWndItem GetHookedWndItem(HWND hWnd);
		BOOL SetHookedWndItem(HWND hWnd, HookWndItem& Item);
		BOOL DeleteHookedWnd(HWND hWnd);
		void ClearHookItem(UINT nItem);

		////
		// Allowed ProcessNames & WindowTitles & Classes WhiteList
		////
		void AddAllowedProcessName(char* strProcessNameInUpperCase);		
		BOOL IsAllowedProcessName(char* strProcessNameInUpperCase);	
		void AddAllowedWindowsTitle(char* strWindowsTitleInUpperCase);		
		BOOL IsAllowedWindowsTitle(char* strWindowsTitleInUpperCase);		
		void AddAllowedWindowsClass(char* strWindowsClassInUpperCase);
		BOOL IsAllowedWindowsClass(char* strWindowsClassInUpperCase);

		////
		// Get/Set and use Logging Detail Levels 
		////
		void SetLoggingDetail(LoggingDetail nLoggingDetailSetting);
		LoggingDetail GetLoggingDetail();
		char* GetLogPath();
		void SetLogPath(char* buf);

		// CRITICAL_SECTION
		void EnterCS();
		void LeaveCS();

		CWHPaccess();
		~CWHPaccess();

	private:		
		////
		// Private functions to keep track of iteration
		////		
		void deltaListTopI(int);		
		
		//Many threads could update the DS. 
		CRITICAL_SECTION cs;
	};
}